*====================== Main diff-in-diff sample ===============================

use "${datadir}\HTB_main_cleaned_feb2016", replace
keep if region == 5 | region == 6


rename pcd postcode_tomatch
joinby postcode_tomatch using "${datadir}\epc-cer_new"

sort postcode_tomatch

gen idate = date(inspection_date, "YMD")
format idate %td

gen diff_date = abs(date - idate)
sum diff_date, det // no one with an inspection later than the sale date

bysort psd_id (diff_date lmk_key): keep if _n == 1

keep psd_id total_floor_area

label data "created by 02_result1_prepare_match_sqm.do"
save "${datadir}\HTB_main_feb2016_sqft", replace





*====================== Placebo sample ===============================
use "${datadir}\HTB_main_cleaned_feb2015_placebo", replace
keep if region == 5 | region == 6

rename pcd postcode_tomatch
joinby postcode_tomatch using "${projectdir}\data\epc-cer_new"

sort postcode_tomatch

gen idate = date(inspection_date, "YMD")

gen diff_date = abs(date - idate)
sum diff_date, det // no one with an inspection later than the sale date

bysort psd_id (diff_date lmk_key): keep if _n == 1

keep psd_id total_floor_area

label data "created by 02_result1_prepare_match_sqm.do"
save "${datadir}\HTB_main_cleaned_feb2015_placebo_sqft", replace
